package com.mate.cloud.sentinel;

import org.redisson.Redisson;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

/**
 * Sentinel 哨兵
 *
 * @author: MI
 * @email: 448341911@qq.com
 * @createTime: 2025/8/22 13:45
 * @updateUser: MI
 * @updateTime: 2025/8/22 13:45
 * @updateRemark: 修改内容
 * @version: 1.0
 */
public class SentinelTest {
    public static void main(String[] args) {
        //创建配置
        Config config = new Config();
        config.setCodec(new org.redisson.client.codec.StringCodec());

        //指定使用哨兵部署方式
        config.useSentinelServers()
                .setPassword("seata@user123")
                .setMasterName("redis-master")
//                .addSentinelAddress("redis://192.168.8.203:26379")
//                .addSentinelAddress("redis://192.168.8.204:26379")
                .addSentinelAddress("redis://192.168.110.36:6379");

        RedissonClient redisson = Redisson.create(config);
        //首先获取redis中的key-value对象，key不存在没关系
        RBucket<String> keyObject = redisson.getBucket("redisson-sitinel-key");
        //如果key存在，就设置key的值为新值value
        //如果key不存在，就设置key的值为value
        keyObject.set("value");

        //最后关闭RedissonClient
        redisson.shutdown();
    }
}
